package design.principle;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;

/**
 * @program JavaBase
 * @description: 依赖倒置
 * @author: zhanglu
 * @create: 2020-03-26 14:02:00
 */
public class DependencyInversion {

    public static void main(String[] args) {

//        IDriver iDriver = new Driver();
//
//        Car01 car01 = new Car01();
//
//        iDriver.driver(car01);
//
//        Car02 car02 = new Car02();
//
//        iDriver.driver(car02);

        //JMock测试
        Mockery mockery = new JUnit4Mockery();
        final ICar iCar = mockery.mock(ICar.class);
        IDriver iDriver = new Driver();
        mockery.checking(new Expectations(){{
            oneOf(iCar).run();
        }});
        iDriver.driver(iCar);

    }

}

interface IDriver {

    void driver(ICar car);

}

interface ICar {

    void run();

}

class Driver implements IDriver{

    @Override
    public void driver(ICar car) {
        System.out.println("我被调用了");
        car.run();
    }
}

class Car01 implements ICar{

    @Override
    public void run() {
        System.out.println("汽车01 - run");
    }

}

class Car02 implements ICar{

    @Override
    public void run() {
        System.out.println("汽车02 - run");
    }

}